package com.deng.config.shiroConfig;

import org.apache.shiro.crypto.hash.Md5Hash;
import org.apache.shiro.crypto.hash.SimpleHash;
import org.apache.shiro.util.ByteSource;

/**
 * @Author 邓小熙
 * @Date 2022/5/3 10:59
 * @Version 1.0
 */
public class ShiroUtil {
    /**
     * 加盐参数
     */
    public final static String hashAlgorithmName = "MD5";

    /**
     * 循环次数
     */
    public final static int hashIterations = 1024;
    /**
     * shiro密码加密工具类
     *
     * @param credentials 密码
     * @param saltSource 密码盐
     * @return
     */
    public static String md5(String credentials,String saltSource){
        ByteSource salt = new Md5Hash(saltSource);
        return new SimpleHash(hashAlgorithmName,credentials,salt,hashIterations).toString();
    }
}
